<?php require("../job/common/pdata_mysql.php"); ?>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<title>全部列表</title>
<link href="/css/layout.css" rel="stylesheet" type="text/css" />
<style type="text/css">
.list {
	width: 960px;
	border-top-width: 1px;
	border-right-width: 1px;
	border-bottom-width: 1px;
	border-left-width: 1px;
}
ul, li {
	margin: 0px;
	padding: 0px;
}
li {
	float: left;
	width: 160px;
	list-style-type: none;
}
</style>
</head>

<body>
<div id="wrap">
  <?php
	$conn = mysql_pconnect($hostname_pdata,$username_pdata,$password_pdata);
?>
  <div id="selectTable">
    <form>
    
      <select style="width:200px" name="table" >
        <option value="stations" <?php  if(isset($_GET['table'])&&($_GET['table'] == "stations")) echo "selected='selected'"; ?>>stations</option>
        <option value="postdoc" <?php  if(isset($_GET['table'])&&($_GET['table'] == "postdoc")) echo "selected='selected'"; ?>>postdoc</option>
        <option value="project" <?php  if(isset($_GET['table'])&&($_GET['table'] == "project")) echo "selected='selected'"; ?>>project</option>
      </select>
      <span >
      <input style="width:200px" type="submit" value="提交" />
      </span>
      <?php 
	if(isset($_GET['table']))
	{
		$table = $_GET['table'];
		mysql_select_db("information_schema");
		$sql = "SELECT column_name FROM columns WHERE table_schema = 'pdata' and table_name = '".$table."'";
		$rs = mysql_query($sql,$conn) or die(mysql_error());
		echo "<ul class='blank'>";
		while($row = mysql_fetch_row($rs))
		{
			echo "<li>";
			echo "<input type='checkbox'  id='".$row[0]."'   name='".$row[0]."' value='1' />";
			echo "<label for='".$row[0]."'>".$row[0]."</label>";
			echo "</li>";
			//echo $row[0]."<br />";
		}
		echo "</ul>";
		//echo $rownum;
	}
	
	
	?>
    </form>
  </div>
  <div id="display">
    <table border="1" class="list">
      <tr>
        <?php
		mysql_select_db("information_schema");
		$sql = "SELECT column_name FROM columns WHERE table_schema = 'pdata' and table_name = '".$table."'";
		$rs = mysql_query($sql,$conn) or die(mysql_error());
	  	
		$sqlTemp =" ";
		while($row = mysql_fetch_row($rs))
		{
			if(isset($_GET[$row[0]]))
			{
				echo "<th>";
				echo $row[0];
				echo "</th>";
				$sqlTemp = $sqlTemp."'".$row[0]."',";
				
			}
		}
		//echo $sqlTemp;
		if(!$sqlTemp)
			$sqlTemp = substr($sqlTemp,0,(strlen($sqlTemp)-1));
		else
			$sqlTemp = "* ";
		//echo $sqlTemp;
	  ?>
      </tr>
      <?php 
		$sql = "select ".$sqlTemp." from ".$table;
		echo $sql;
		mysql_select_db("pdata");
		$rsdata = mysql_query($sql,$conn) or die(mysql_error());
		//echo $rsData;
		while($rowdata = mysql_fetch_array($rsdata))
		{
			
				$rownum = mysql_num_fields($rsdata);
				for($i=0;$i<$rownum;$i++)
				{while($proper = mysql_fetch_field($rsdata,$i))
					{
					if(isset($_GET[$proper->name]) && ($_GET[$proper->name]==1))
						{
						echo "<tr>";
						echo "<td>".$rowdata[$proper->name]."</td>";
						//echo "<td>"."<a target='_new' href='st_edit.php?modi=修改&stid=".$row['StID']."'>编辑</a> | <a target='_new' href='st_del.php?stid=".$row['StID']."'>删除</a>"."</td>";
						echo "</tr>";
						}
					}
				}
		}
		mysql_close($conn);

	?>
    </table>
  </div>
</div>
</body>
</html>